#ifndef _GPIO_H
#define _GPIO_H

#include <pthread.h>

int GPIO_OutEnable(int fd, unsigned int dwEnBits);
int GPIO_OutDisable(int fd, unsigned int dwDisBits);
int GPIO_OpenDrainEnable(int fd, unsigned int dwODBits);
int GPIO_OutSet(int fd, unsigned int dwSetBits);
int GPIO_OutClear(int fd, unsigned int dwClearBits);
int GPIO_PinState(int fd, unsigned int* pPinState);

#define VH_Back 3 //gpio3, used to check if sampling lid is exist

#define GET_VH_Back(x)  !!((x)&(1<<VH_Back))

class CGpio 
{ 
public: 
     static pthread_mutex_t mutex; 
     static CGpio* getInstance();
     ~CGpio();
     
private: 
     static CGpio* pInstance;
     CGpio();
	//把复制构造函数和=操作符也设为私有,防止被复制
     CGpio(const CGpio&);
     CGpio& operator=(const CGpio&);
     
     //destroy the instance of CGpio when the program end
     private:
        class GGGarbo
        {
            public:
                ~GGGarbo()
                {
                    if(CGpio::pInstance != NULL)
                    {
                        delete CGpio::pInstance;
                        CGpio::pInstance = NULL;
                    }
                }
        };

public:
    int GPIO_OutEnable(unsigned int dwEnBits);
    int GPIO_OutDisable(unsigned int dwDisBits);
    //int GPIO_OpenDrainEnable(unsigned int dwODBits);
    int GPIO_OutSet(unsigned int dwSetBits);
    int GPIO_OutClear(unsigned int dwClearBits);
    int GPIO_PinState(unsigned int* pPinState);
    void openDev(void);
    void closeDev(void);
private:
    int fd;   
}; 
 





#endif
